 	

var Cdata = function (name, value)
{
    return '<'+name+'><![CDATA['+value+']]></'+name+'>';
};
var Read = function (element) { return element.firstChild?element.firstChild.nodeValue:element.nodeValue; };

var invoke = function (data, nodename, action, array, proxy, callback) // invoke                                                                                                                                                                                                                                                                               
{
    var mhttp=XmlHttp.create();//new ActiveXObject("Msxml2.XMLHTTP");                                                                                                                                                                                                                                                                      
    mhttp.open("POST", this.endpoint, callback ? true : false);    
    mhttp.setRequestHeader('SOAPAction',action);
    window.asyncontroller=this;
    if (callback)
    {                                                                                                                                                                                                
        mhttp.onreadystatechange = function ()                                              
        {                                              
            if (mhttp.readyState == 4)                                              
            {    
                var args = new PIMPConnectorEventArgs ();
                args.State = mhttp.status;
                if (mhttp.status==200)
                {
                    args.Result=window.asyncontroller.deserialize (mhttp.responseText, nodename, proxy);  
                }
                else
                {
                    args.Error = "URL responded with an error";
                }
                callback (window.asyncontroller, args);                                              
            }  
        }                                          
    }
    mhttp.send( this.envelope(data) );       
    if (callback) return true;        
    var result=this.deserialize (mhttp.responseText, nodename, proxy); 
    return array ? result : result[0];    
} // invoke  

var deserialize = function (data, nodename, proxy)
{
    var mdom=XmlDocument.create(); 
    var result=new Array();
    if (mdom.loadXML (data))
    { 
        var nodes = mdom.getElementsByTagName(nodename); 
        for (var i=0;i<nodes.length;i++)
        { 
            if (proxy)
            { 
                var tmp_proxy=proxy.create();
                tmp_proxy.deserialize (nodes[i]);
                result[result.length]=tmp_proxy;     
            } else result[result.length]=Read(nodes[i]);         
        }
    } else alert ("The response was not well-formed XML.\n"+data);
    return result;
};

var envelope = function (data)
{
    var output='';
    output+='<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"';  
    output+=' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"';  
    output+=' xmlns:xsd="http://www.w3.org/2001/XMLSchema">';                            
    output+='<soap:Body>' + data;  

    output+='</soap:Body>';  
    output+='</soap:Envelope>';  
    return output;
};
 



var PIMPConnector = {
    create : function ()
    {
        return {

    // GetPictures methods 
            GetPicturesRequest : function ()
            {
                var request="<GetPictures xmlns=\"" + this.namespace + "\">";
                request+="</GetPictures>";
                return request;        
            },    
            GetPictures : function ()
            {
                var request=this.GetPicturesRequest ();
                return this.invoke (request, "GetPicturesResult", "http://www.cyber8.net/webservices/pimp/GetPictures", true, PPicture);
            },    
            GetPicturesAsync : function ()
            {
                var request=this.GetPicturesRequest ();
                return this.invoke (request, "GetPicturesResult", "http://www.cyber8.net/webservices/pimp/GetPictures", true, PPicture, this.GetPicturesCompleted);
            },    
            GetPicturesCompleted : function (sender, e)
            { // add your handler code for this event
                alert (e.Result);
            }, 

    // GetPicture methods 
            GetPictureRequest : function (id)
            {
                var request="<GetPicture xmlns=\"" + this.namespace + "\">"; 
                request+=Cdata ('id', id);
                request+="</GetPicture>";
                return request;        
            },    
            GetPicture : function (id)
            {
                var request=this.GetPictureRequest (id);
                return this.invoke (request, "GetPictureResult", "http://www.cyber8.net/webservices/pimp/GetPicture", false, PPicture);
            },    
            GetPictureAsync : function (id)
            {
                var request=this.GetPictureRequest (id);
                return this.invoke (request, "GetPictureResult", "http://www.cyber8.net/webservices/pimp/GetPicture", false, PPicture, this.GetPictureCompleted);
            },    
            GetPictureCompleted : function (sender, e)
            { // add your handler code for this event
                alert (e.Result);
            }, 

    // DeletePicture methods 
            DeletePictureRequest : function (id)
            {
                var request="<DeletePicture xmlns=\"" + this.namespace + "\">"; 
                request+=Cdata ('id', id);
                request+="</DeletePicture>";
                return request;        
            },    
            DeletePicture : function (id)
            {
                var request=this.DeletePictureRequest (id);
                return this.invoke (request, "DeletePictureResult", "http://www.cyber8.net/webservices/pimp/DeletePicture", false, false);
            },    
            DeletePictureAsync : function (id)
            {
                var request=this.DeletePictureRequest (id);
                return this.invoke (request, "DeletePictureResult", "http://www.cyber8.net/webservices/pimp/DeletePicture", false, false, this.DeletePictureCompleted);
            },    
            DeletePictureCompleted : function (sender, e)
            { // add your handler code for this event
                alert (e.Result);
            }, 
    // ApplyTool methods 
            ApplyToolRequest : function (id, tool, brush, color, coords)
            {
                var request="<ApplyTool xmlns=\"" + this.namespace + "\">"; 
                request+=Cdata ('id', id); 
                request+=Cdata ('tool', tool); 
                request+=Cdata ('brush', brush); 
                request+=Cdata ('color', color); 
                request+=Cdata ('coords', coords);
                request+="</ApplyTool>";
                return request;        
            },    
            ApplyTool : function (id, tool, brush, color, coords)
            {
                var request=this.ApplyToolRequest (id, tool, brush, color, coords);
                return this.invoke (request, "ApplyToolResult", "http://www.cyber8.net/webservices/pimp/ApplyTool", false, false);
            },    
            ApplyToolAsync : function (id, tool, brush, color, coords)
            {
                var request=this.ApplyToolRequest (id, tool, brush, color, coords);
                return this.invoke (request, "ApplyToolResult", "http://www.cyber8.net/webservices/pimp/ApplyTool", false, false, this.ApplyToolCompleted);
            },    
            ApplyToolCompleted : function (sender, e)
            { // add your handler code for this event
                alert (e.Result);
            }, 

     // ResetImage methods 
            ResetImageRequest : function (id)
            {
                var request="<ResetImage xmlns=\"" + this.namespace + "\">"; 
                request+=Cdata ('id', id);
                request+="</ResetImage>";
                return request;        
            },    
            ResetImage : function (id)
            {
                var request=this.ResetImageRequest (id);
                return this.invoke (request, "ResetImageResult", "http://www.cyber8.net/webservices/pimp/ResetImage", false, false);
            },    
            ResetImageAsync : function (id)
            {
                var request=this.ResetImageRequest (id);
                return this.invoke (request, "ResetImageResult", "http://www.cyber8.net/webservices/pimp/ResetImage", false, false, this.ResetImageCompleted);
            },    
            ResetImageCompleted : function (sender, e)
            { // add your handler code for this event
                alert (e.Result);
            }, 

    // GetPixelAt methods 
            GetPixelAtRequest : function (id, x, y)
            {
                var request="<GetPixelAt xmlns=\"" + this.namespace + "\">"; 
                request+=Cdata ('id', id); 
                request+=Cdata ('x', x); 
                request+=Cdata ('y', y);
                request+="</GetPixelAt>";
                return request;        
            },    
            GetPixelAt : function (id, x, y)
            {
                var request=this.GetPixelAtRequest (id, x, y);
                return this.invoke (request, "GetPixelAtResult", "http://www.cyber8.net/webservices/pimp/GetPixelAt", false, false);
            },    
            GetPixelAtAsync : function (id, x, y)
            {
                var request=this.GetPixelAtRequest (id, x, y);
                return this.invoke (request, "GetPixelAtResult", "http://www.cyber8.net/webservices/pimp/GetPixelAt", false, false, this.GetPixelAtCompleted);
            },    
            GetPixelAtCompleted : function (sender, e)
            { // add your handler code for this event
                alert (e.Result);
            }, 


    // GetPictureLog methods 
            GetPictureLogRequest : function (id)
            {
                var request="<GetPictureLog xmlns=\"" + this.namespace + "\">"; 
                request+=Cdata ('id', id);
                request+="</GetPictureLog>";
                return request;        
            },    
            GetPictureLog : function (id)
            {
                var request=this.GetPictureLogRequest (id);
                return this.invoke (request, "GetPictureLogResult", "http://www.cyber8.net/webservices/pimp/GetPictureLog", true, ToolInfo);
            },    
            GetPictureLogAsync : function (id)
            {
                var request=this.GetPictureLogRequest (id);
                return this.invoke (request, "GetPictureLogResult", "http://www.cyber8.net/webservices/pimp/GetPictureLog", true, ToolInfo, this.GetPictureLogCompleted);
            },    
            GetPictureLogCompleted : function (sender, e)
            { // add your handler code for this event
                alert (e.Result);
            }, 

    // ApplyPictureLog methods 
            ApplyPictureLogRequest : function (id, step)
            {
                var request="<ApplyPictureLog xmlns=\"" + this.namespace + "\">"; 
                request+=Cdata ('id', id); 
                request+=Cdata ('step', step);
                request+="</ApplyPictureLog>";
                return request;        
            },    
            ApplyPictureLog : function (id, step)
            {
                var request=this.ApplyPictureLogRequest (id, step);
                return this.invoke (request, "ApplyPictureLogResult", "http://www.cyber8.net/webservices/pimp/ApplyPictureLog", false, false);
            },    
            ApplyPictureLogAsync : function (id, step)
            {
                var request=this.ApplyPictureLogRequest (id, step);
                return this.invoke (request, "ApplyPictureLogResult", "http://www.cyber8.net/webservices/pimp/ApplyPictureLog", false, false, this.ApplyPictureLogCompleted);
            },    
            ApplyPictureLogCompleted : function (sender, e)
            { // add your handler code for this event
                alert (e.Result);
            }, 

            deserialize  : deserialize,
            envelope     : envelope,
            invoke       : invoke,
            endpoint     : 'http://www.101stratford.com/pimp/ns-webservice.php',
            namespace    : 'http://www.cyber8.net/webservices/pimp'  
        }
    }
}
	
function PIMPConnectorEventArgs (a_result, a_state, a_error)
{
    this.Result=a_result;
    this.State=a_result;
    this.Error=a_error;
}

 
var PPicture = {
    create : function ()
    {
        return {
            name:null,
            url:null,
            size:null,
            id:null,
            
            deserialize:function(element)
            {
                for (var x=0;x<element.childNodes.length;x++)
                {
                    var child = element.childNodes[x];
                    var value = Read(child); 
                    if (value) this[child.nodeName] = value; 
                }
            }
        }
    }
}

 
var ToolInfo = {
    create : function ()
    {
        return {
            name:null,
            brush:null,
            color:null,
            coords:null,
            
            deserialize:function(element)
            {
                for (var x=0;x<element.childNodes.length;x++)
                {
                    var child = element.childNodes[x];
                    var value = Read(child); 
                    if (value) this[child.nodeName] = value; 
                }
            }
        }
    }
}

